package com.sebklebes.radar.gae.converter;

import com.sebklebes.radar.gae.entity.RadarEntity;

import java.util.List;
import java.util.logging.Logger;

/**
 * Converts the radar entities to response strings.
 * Note: test class.
 * TODO - send data in json (or other) format.
 *
 * @author Ioana Sebestyen
 */
public class RadarConverter {

	private static Logger logger = Logger.getLogger(RadarConverter.class.getName());

	/**
	 * Converts a list of radar entities to a response string.
	 *
	 * @param radarEntityList the list of radar entities
	 * @return the response string
	 */
	public static String convertRadarArrayToString(List<RadarEntity> radarEntityList) {
		StringBuilder stringBuilder = new StringBuilder();

		for (int i = 0; i < radarEntityList.size() - 1; i++) {
			RadarEntity radarEntity = radarEntityList.get(i);
			stringBuilder
					.append(radarEntity.getKey().getId())
					.append(",")
//					.append(radarEntity.getLatitude())
//					.append(",")
//					.append(radarEntity.getLongitude())
					.append(radarEntity.getDistance())
					.append(";");
		}

		RadarEntity radarEntity = radarEntityList.get(radarEntityList.size() - 1);
		stringBuilder
				.append(radarEntity.getKey().getId())
				.append(",")
//				.append(radarEntity.getLatitude())
//				.append(",")
//				.append(radarEntity.getLongitude());
				.append(radarEntity.getDistance());
		logger.info(stringBuilder.toString());
		return stringBuilder.toString();
	}

	/**
	 * Converts a radar to a response string.
	 *
	 * @param radarEntity the radar entities
	 * @return the response string
	 */
	public static String convertRadarToString(RadarEntity radarEntity) {
		StringBuilder stringBuilder = new StringBuilder();

		stringBuilder
				.append(radarEntity.getKey().getId())
				.append(",")
				.append(radarEntity.getLatitude())
				.append(",")
				.append(radarEntity.getLongitude());

		logger.info(stringBuilder.toString());
		return stringBuilder.toString();
	}
}
